package com.itheima.ai.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY;

@RestController
@RequestMapping("/ai")
public class GameController {


    @Autowired
    private ChatClient honghongClient;
    @GetMapping(value = "/game", produces = "text/html;charset=UTF-8")
    public Flux<String> HonghngGame(@RequestParam(value = "prompt") String prompt, String chatId) {
        Flux<String> contents = honghongClient.prompt()
                .user(prompt)
                .advisors(advisorSpec -> advisorSpec.param(CHAT_MEMORY_CONVERSATION_ID_KEY,chatId))
                .stream()
                .content();
        return contents;
    }
}
